package com.example.tbag.healthcare.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.tbag.healthcare.Model.DragInfo;
import com.example.tbag.healthcare.Model.HumanInfo;
import com.example.tbag.healthcare.R;

import java.util.List;

/**
 * Created by tbag on 2017/4/21.
 */

public class HealthListAdapter extends BaseAdapter {
    private List<HumanInfo> humanInfos;
    private List<DragInfo> dragInfos;
    private LayoutInflater mInflater;
    private Context context;
    
    private static final int HUMANINFO =0;
    private static final int DILIVER = 1;
    private static final int DRAGiNFO = 2;
    
    
    public HealthListAdapter(List<HumanInfo> list, List<DragInfo> list1, Context context){
        humanInfos = list;
        dragInfos = list1;
        mInflater = LayoutInflater.from(context);
        this.context = context;
    }
    
    
    @Override
    public int getCount() {
        return humanInfos.size()+dragInfos.size()+1;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public int getViewTypeCount() {
        return 3;
    }

    @Override
    public int getItemViewType(int position) {
        if(position<humanInfos.size()){
            return HUMANINFO;
        }else if(position == humanInfos.size()){
            return DILIVER;
        }else{
            return DRAGiNFO;
        }
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        if (getItemViewType(position) == HUMANINFO) {
            ViewHolder holder;
            if (convertView == null) {
                convertView = mInflater.inflate(R.layout.layout_human_info_list, null);
                holder = new ViewHolder();
                holder.name = (TextView) convertView.findViewById(R.id.edit1);
                holder.sex = (TextView) convertView.findViewById(R.id.edit2);
                holder.age = (TextView) convertView.findViewById(R.id.edit3);
                holder.type = (TextView) convertView.findViewById(R.id.edit4);
                holder.bed = (TextView) convertView.findViewById(R.id.edit5);
                holder.bt = (TextView) convertView.findViewById(R.id.edit6); // to ItemButton
                holder.bt1 = (TextView) convertView.findViewById(R.id.edit7);
                holder.bt2 = (TextView) convertView.findViewById(R.id.edit8);
                convertView.setTag(holder); //绑定ViewHolder对象
            } else {
                holder = (ViewHolder) convertView.getTag(); //取出ViewHolder对象
            }
            final HumanInfo humanInfo = humanInfos.get(position);
            holder.name.setText(humanInfo.date);
            holder.sex.setText(humanInfo.time);
            holder.age.setText(humanInfo.temper);
            holder.bed.setText(humanInfo.pulse);
            holder.type.setText(humanInfo.breath);
            holder.bt.setText(humanInfo.blood);
            holder.bt1.setText(humanInfo.sugar);
            holder.bt2.setText(humanInfo.eg);
        } else if (getItemViewType(position) == DILIVER) {
            convertView = mInflater.inflate(R.layout.layout_diliver, null);
        } else {
            ViewHolder1 holder1;
            if (convertView == null) {
                convertView = mInflater.inflate(R.layout.layout_drag_info_list, null);
                holder1 = new ViewHolder1();
                holder1.name = (TextView) convertView.findViewById(R.id.edit1);
                holder1.sex = (TextView) convertView.findViewById(R.id.edit2);
                holder1.age = (TextView) convertView.findViewById(R.id.edit3);
                holder1.bed = (TextView) convertView.findViewById(R.id.edit4);
                holder1.bed1 = (TextView) convertView.findViewById(R.id.edit5);
                holder1.bed2 = (TextView) convertView.findViewById(R.id.edit6);
                holder1.bed3 = (TextView) convertView.findViewById(R.id.edit7);
                convertView.setTag(holder1); //绑定ViewHolder对象
            } else {
                holder1 = (ViewHolder1) convertView.getTag(); //取出ViewHolder对象
            }
            final DragInfo dragInfo = dragInfos.get(position);
            holder1.name.setText(dragInfo.time);
            holder1.sex.setText(dragInfo.drag);
            holder1.age.setText(dragInfo.count);
            holder1.bed.setText(dragInfo.done);
        }
        return convertView;
    }

    public final class ViewHolder {
        public TextView name;
        public TextView sex;
        public TextView age;
        public TextView bed;
        public TextView type;
        public TextView bt;
        public TextView bt1;
        public TextView bt2;
    }

    public final class ViewHolder1 {
        public TextView name;
        public TextView sex;
        public TextView age;
        public TextView bed;
        public TextView bed1;
        public TextView bed2;
        public TextView bed3;
    }
}
